package com.itheima.controller;


import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.Utils.ValidateCodeUtils;
import com.itheima.common.MessageConst;
import com.itheima.common.RedisMessageConstant;
import com.itheima.entity.Result;
import com.itheima.service.ValidateCodeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @ClassName ValidateCodeController
 * @Description: TODO
 * @Author 郑乾
 * @Date 2020-06-29
 * @Version V1.0
 **/
@RestController
@RequestMapping("/validateCode")
@Slf4j
public class ValidateCodeController {
    @Reference
    ValidateCodeService validateCodeService;

    @RequestMapping("send4Login")
    public Result send4Login(String telephone) {
        String code = ValidateCodeUtils.generateValidateCode(6).toString();
        log.debug("验证码:" + code);
        validateCodeService.sendValidateCodeShortMessage(telephone, RedisMessageConstant.SENDTYPE_LOGIN, String.valueOf(code));
        log.debug("发送验证码成功");
        return new Result(true, MessageConst.SEND_VALIDATECODE_SUCCESS);
    }

    @RequestMapping("send4Order")
    public Result send4Order(String telephone) {
        String code = ValidateCodeUtils.generateValidateCode(6).toString();
        log.debug("验证码:" + code);
        validateCodeService.sendValidateCodeShortMessage(telephone, RedisMessageConstant.SENDTYPE_ORDER, String.valueOf(code));
        return new Result(true, MessageConst.SEND_VALIDATECODE_SUCCESS);
    }
}
